<template>
    <div class="flex column h-100">
        <page-header></page-header>
        <div class="bg-grey flex-1 overflow-hide relative ui-body-min-height"  v-if="ready">
            <router-view></router-view>
        </div>
    </div>
</template>

<script>
    import pageHeader from '@/views/header'
    export default {
        components: {
            pageHeader,
        },
        data () {
            return {
                ready: false
            }
        },
        computed:{
            isMobile() {//检测是否移动端
                if (navigator.userAgent.match(/Android/i)
                    || navigator.userAgent.match(/webOS/i)
                    || navigator.userAgent.match(/iPhone/i)
                    || navigator.userAgent.match(/iPad/i)
                    || navigator.userAgent.match(/iPod/i)
                    || navigator.userAgent.match(/BlackBerry/i)
                    || navigator.userAgent.match(/Windows Phone/i)
                ) {
                    return true;
                }
                else {
                    return false;
                }
            }
        },
        created () {
            // 若移动端访问, 跳转到移动端网址
            if (this.isMobile) {
                location.href = location.href.replace('/pc','')
            }

            let loading = this.$loading({ fullscreen: true, text:'王大虎' })

            // 获取用户数据
            this.$http.get('index.php?g=home&m=Users&a=user_info')
            .then(({data})=>{
                // console.log('用户数据', data);
                loading.close()
                this.ready = true
                if (data.code===1) {
                    this.$store.commit({
                        type: 'update', //mutaitions 操作数据类型
                        data: data.data,//要保存的数据
                        modules: 'userInfo' //保存到哪个模块
                    })
                }
            }).catch(() => {
                loading.close()
                console.error('网络异常,基础数据获取失败');
            })

        },
    }
</script>
